const Mock = require('mockjs')

const data = Mock.mock({
  'items|12': [{
    resourceId: '@id',
    resourceName: '@integer(10, 1000000)',
    resourceCode: '789',
    appCode: '123',
    serviceCode: '456',
    resourceUrl: '12345',
    httpMethod: '@integer(10, 50)',
    isRelate: '1|2',
    modularName: 'dqwdq',
    sort: '1',
    version: '3.0'
  }],
  roles: [{
    roleId: '@id',
    roleCode: '@integer(10, 50)',
    roleName: '@roleName',
    roleType: '@integer(1, 10)',
    appName: '@appName',
    isSelected: '1|0'
  }],
  menulist: [
    {
      id: '1',
      parentId: '-1',
      code: '',
      name: '用户中心',
      logo: 'user',
      level: 1, // 1应用 2菜单 3按钮
      type: 0, // 1菜单 2按钮
      appId: '@id',
      children: [
        { id: '2',
          parentId: '1',
          code: 'user',
          name: '用户管理',
          logo: '',
          level: 2,
          type: 1,
          children: [{
            id: '3',
            parentId: '2',
            code: '',
            name: '新增',
            logo: '',
            level: 3,
            type: 2,
            children: null
          }, {
            id: '4',
            parentId: '2',
            code: '',
            name: '删除',
            logo: '',
            level: 3,
            type: 2,
            children: null
          }]
        },
        { id: '5',
          parentId: '1',
          code: '',
          name: '组织管理',
          logo: '',
          type: 1,
          level: 2,
          children: null
        }
      ]
    }
  ],
  data: [
    {
      appId: '1',
      appCode: 'string',
      appName: '用户中心应用',
      checked: false,
      serviceList: [
        {
          serviceId: '2',
          serviceCode: 'string',
          serviceName: '用户中心服务',
          checked: false,
          modularList: [
            {
              modularCode: '3',
              modularName: '用户中心类',
              checked: false,
              resourceList: [
                {
                  createTime: 'string',
                  createUser: 'string',
                  updateTime: 'string',
                  updateUser: 'string',
                  delFlag: 'string',
                  resourceName: '获取用户列表',
                  resourceId: '4',
                  resourceCode: 'string',
                  url: 'string',
                  appId: 'string',
                  appCode: 'string',
                  serviceCode: 'string',
                  version: 'string',
                  httpMethod: 'string',
                  modularName: 'string',
                  sort: 0,
                  isRelate: true,
                  checked: false
                },
                {
                  createTime: 'string',
                  createUser: 'string',
                  updateTime: 'string',
                  updateUser: 'string',
                  delFlag: 'string',
                  resourceName: '新增用户',
                  resourceId: '5',
                  resourceCode: 'string',
                  url: 'string',
                  appId: 'string',
                  appCode: 'string',
                  serviceCode: 'string',
                  version: 'string',
                  httpMethod: 'string',
                  modularName: 'string',
                  sort: 0,
                  isRelate: true,
                  checked: false
                }
              ]
            },
            {
              modularCode: '322',
              modularName: '用户中心类22',
              checked: true,
              resourceList: [
                {
                  createTime: 'string',
                  createUser: 'string',
                  updateTime: 'string',
                  updateUser: 'string',
                  delFlag: 'string',
                  resourceName: '获取用户列表22',
                  resourceId: '422',
                  resourceCode: 'string',
                  url: 'string',
                  appId: 'string',
                  appCode: 'string',
                  serviceCode: 'string',
                  version: 'string',
                  httpMethod: 'string',
                  modularName: 'string',
                  sort: 0,
                  isRelate: true,
                  checked: true
                },
                {
                  createTime: 'string',
                  createUser: 'string',
                  updateTime: 'string',
                  updateUser: 'string',
                  delFlag: 'string',
                  resourceName: '新增用户22',
                  resourceId: '522',
                  resourceCode: 'string',
                  url: 'string',
                  appId: 'string',
                  appCode: 'string',
                  serviceCode: 'string',
                  version: 'string',
                  httpMethod: 'string',
                  modularName: 'string',
                  sort: 0,
                  isRelate: true,
                  checked: true
                }
              ]
            }
          ]
        },
        {
          serviceId: '22',
          serviceCode: 'string',
          serviceName: '用户中心服务2',
          checked: false,
          modularList: [
            {
              modularCode: '32',
              modularName: '用户中心类2',
              checked: false,
              resourceList: [
                {
                  createTime: 'string',
                  createUser: 'string',
                  updateTime: 'string',
                  updateUser: 'string',
                  delFlag: 'string',
                  resourceName: '获取用户列表2',
                  resourceId: '42',
                  resourceCode: 'string',
                  url: 'string',
                  appId: 'string',
                  appCode: 'string',
                  serviceCode: 'string',
                  version: 'string',
                  httpMethod: 'string',
                  modularName: 'string',
                  sort: 0,
                  isRelate: true,
                  checked: false
                },
                {
                  createTime: 'string',
                  createUser: 'string',
                  updateTime: 'string',
                  updateUser: 'string',
                  delFlag: 'string',
                  resourceName: '新增用户2',
                  resourceId: '52',
                  resourceCode: 'string',
                  url: 'string',
                  appId: 'string',
                  appCode: 'string',
                  serviceCode: 'string',
                  version: 'string',
                  httpMethod: 'string',
                  modularName: 'string',
                  sort: 0,
                  isRelate: false,
                  checked: false
                },
                {
                  createTime: 'string',
                  createUser: 'string',
                  updateTime: 'string',
                  updateUser: 'string',
                  delFlag: 'string',
                  resourceName: '获取用户列表2',
                  resourceId: '62',
                  resourceCode: 'string',
                  url: 'string',
                  appId: 'string',
                  appCode: 'string',
                  serviceCode: 'string',
                  version: 'string',
                  httpMethod: 'string',
                  modularName: 'string',
                  sort: 0,
                  isRelate: true,
                  checked: false
                },
                {
                  createTime: 'string',
                  createUser: 'string',
                  updateTime: 'string',
                  updateUser: 'string',
                  delFlag: 'string',
                  resourceName: '新增用户2',
                  resourceId: '72',
                  resourceCode: 'string',
                  url: 'string',
                  appId: 'string',
                  appCode: 'string',
                  serviceCode: 'string',
                  version: 'string',
                  httpMethod: 'string',
                  modularName: 'string',
                  sort: 0,
                  isRelate: false,
                  checked: false
                },
                {
                  createTime: 'string',
                  createUser: 'string',
                  updateTime: 'string',
                  updateUser: 'string',
                  delFlag: 'string',
                  resourceName: '获取用户列表2',
                  resourceId: '82',
                  resourceCode: 'string',
                  url: 'string',
                  appId: 'string',
                  appCode: 'string',
                  serviceCode: 'string',
                  version: 'string',
                  httpMethod: 'string',
                  modularName: 'string',
                  sort: 0,
                  isRelate: true,
                  checked: false
                },
                {
                  createTime: 'string',
                  createUser: 'string',
                  updateTime: 'string',
                  updateUser: 'string',
                  delFlag: 'string',
                  resourceName: '新增用户2',
                  resourceId: '92',
                  resourceCode: 'string',
                  url: 'string',
                  appId: 'string',
                  appCode: 'string',
                  serviceCode: 'string',
                  version: 'string',
                  httpMethod: 'string',
                  modularName: 'string',
                  sort: 0,
                  isRelate: false,
                  checked: false
                },
                {
                  createTime: 'string',
                  createUser: 'string',
                  updateTime: 'string',
                  updateUser: 'string',
                  delFlag: 'string',
                  resourceName: '获取用户列表2',
                  resourceId: '102',
                  resourceCode: 'string',
                  url: 'string',
                  appId: 'string',
                  appCode: 'string',
                  serviceCode: 'string',
                  version: 'string',
                  httpMethod: 'string',
                  modularName: 'string',
                  sort: 0,
                  isRelate: true,
                  checked: false
                },
                {
                  createTime: 'string',
                  createUser: 'string',
                  updateTime: 'string',
                  updateUser: 'string',
                  delFlag: 'string',
                  resourceName: '新增用户2',
                  resourceId: '112',
                  resourceCode: 'string',
                  url: 'string',
                  appId: 'string',
                  appCode: 'string',
                  serviceCode: 'string',
                  version: 'string',
                  httpMethod: 'string',
                  modularName: 'string',
                  sort: 0,
                  isRelate: false,
                  checked: false
                },
                {
                  createTime: 'string',
                  createUser: 'string',
                  updateTime: 'string',
                  updateUser: 'string',
                  delFlag: 'string',
                  resourceName: '获取用户列表2',
                  resourceId: '122',
                  resourceCode: 'string',
                  url: 'string',
                  appId: 'string',
                  appCode: 'string',
                  serviceCode: 'string',
                  version: 'string',
                  httpMethod: 'string',
                  modularName: 'string',
                  sort: 0,
                  isRelate: true,
                  checked: false
                },
                {
                  createTime: 'string',
                  createUser: 'string',
                  updateTime: 'string',
                  updateUser: 'string',
                  delFlag: 'string',
                  resourceName: '新增用户2',
                  resourceId: '132',
                  resourceCode: 'string',
                  url: 'string',
                  appId: 'string',
                  appCode: 'string',
                  serviceCode: 'string',
                  version: 'string',
                  httpMethod: 'string',
                  modularName: 'string',
                  sort: 0,
                  isRelate: false,
                  checked: false
                }
              ]
            }
          ]
        }
      ]
    }
  ]
})
module.exports = [
  {
    url: '/app/getAppMenuList', // 系统配置-接口权限配置-左侧应用菜单树
    type: 'get',
    response: (config) => {
      const items = data.menulist
      return {
        code: '00000',
        success: 'true',
        message: 'success',
        data: items
      }
    }
  },
  // 系统配置-接口权限配置-右侧接口列表分页查询（带查询条件）
  {
    url: '/resource/getApiResource',
    type: 'get',
    response: (config) => {
      const { items } = data
      const { pageNo = 1, pageSize = 10 } = config.query
      const pageList = items.filter((item, index) => index < pageSize * pageNo && index >= pageSize * (pageNo - 1))
      return {
        code: '00000',
        data: {
          totalRows: items.length,
          rows: pageList
        }
      }
    }
  },
  // 获取应用下所有的接口资源（不分页）
  {
    url: '/resource/getApiByAppServiceList',
    type: 'get',
    response: (config) => {
      const items = data.data
      return {
        code: '00000',
        success: 'true',
        message: 'success',
        data: items
      }
    }
  },
  // 关联接口绑定
  {
    url: '/allocate/relateApi',
    type: 'post',
    response: (_) => {
      return {
        code: '00000',
        success: true,
        message: 'success',
        data: 'success'
      }
    }
  },
  // 解除关联接口绑定
  {
    url: '/allocate/unrelateApi',
    type: 'post',
    response: (_) => {
      return {
        code: '00000',
        success: true,
        message: 'success',
        data: 'success'
      }
    }
  }
]
